<template>
	<view>
		<view class="kong"></view>
		<block v-if="list.length>0 ">
		<block v-for="(item,index) in list" :key="index">
			<view class="body"  @click="goResult(item.id)">
				<view class="bodyTop dis dis1 dis2">
					<view class="toitem dis">
						<view class="topLeft">
							<view class="tipTilte">{{item.title}}</view>
							<view class="tipTilte1">{{item.time}} 完成测评</view>
						</view>
						<view class="topRigth">
							<image :src="item.pic" mode="aspectFit" class="cep_1"></image>
						</view>
					</view>
				</view>
				<view class="bodyBoom dis dis2 dis3">
					<view class="botmLeft dis dis2">测评结果：{{item.result}}</view>
					<view class="botmRigth dis dis2 dis3">
						<text>查看完整结果</text>
						<image src="../../../static/img/jiao.png" mode="aspectFit" class="jiao"></image>
					</view>
				</view>
			</view>
		</block>
		</block>
		
		<block  v-if="!isShow && list.length<=0">
			<ques :text1="text1" :text2="text2" :text3="text3"></ques>
			
		</block>
	</view>
</template>

<script>
	let app = getApp().globalData;
	import result from '../../../common/js/indexFx.js';
	import ques from '../../../components/quesheng.vue';
	export default {
		components:{
			ques
		},
		data() {
			return {
				list: [],
				is: true,
				id: 0,
				isShow:true,
				text1:'你还没有测评记录',
				text2:'快去测评吧',
				text3:'立刻测评',
				
			};
		},
		methods: {
			getData(lastid) {
				let that = this;
				let id = that.id;
				let ids = 0;
				let list = this.list;
				this.$http._post('user/testhistory.do', {
					lastid: lastid
				}).then(res => {
					console.log(res)
					if (res.data.issuccess == 1) {
						let {
							data
						} = res.data;
						for (let j = 0; j < data.length; j++) {
							if (data[j].result == '') {
								data[j].result = '正常'
							}
						}
						if (data.length <= 0) {
							that.is = false;
							that.isShow=false;
							return
						}
						for (let i = 0; i < data.length; i++) {
							if (i == data.length - 1) {
								ids = data[i].id
							}
						}
						console.log('最新一条记录的ids', ids)
						console.log('上一次最后一条记录的id', id)
						if (ids == id) {
							that.is = false
						} else {
							that.id = ids;
							if (list.length <= 0) {
								that.list = data;
							} else {
								list.push.apply(list, data);
								that.list = list;
							}
						}
					}
				})
			},
			goResult(id) {
				let that = this;
				this.$http._post('test/getresult.do', {
					subjectid: id
				}).then(res => {
						// console.log(res)
					if (res.data.issuccess == 1) {
						let {
							data
						} = res.data;
						app.resultData = data;
						let obj = result.splitting(data);
						app.listValue = obj.listValue;
						app.listName = obj.listName;
						console.log(obj)
						let daily = obj.daily;
						uni.navigateTo({
							url: `../result/result?daily=${daily}`
						})
					}
					// console.log(res)
				})
			},
			goUrl(){
				uni.reLaunch({
					url:'/pages/appraisal/appraisal'
				})
			}
		},
		onLoad() {
			this.getData(0)
		},
		onReachBottom() {
			let is = this.is;
			let id = this.id;
			if (is) {
				this.getData(id)
			} else {
				this.$http.isMssage('暂无更多数据')
			}
		}

	}
</script>

<style lang="scss" scoped>
	@import "../../../common/css/flex.css";
	@import "../../../common/css/index.scss";

	.kong {
		width: 100%;
		height: 48upx;
	}

	.body {
		width: 686upx;
		height: 279upx;
		margin: auto;
		margin-bottom: 32upx;
		background-image: url(../../../static/image/bgsto.png);
		background-size: 100% 100%;

		.bodyTop {
			height: 182upx;
			width: 624upx;
			border-bottom: 1px dashed #EAEAEA;
			margin: auto;

			.toitem {
				width: 100%;
				height: 136upx;

				.topLeft {
					width: 484upx;
					height: 100%;

					.tipTilte {
						font-size: 32upx;
						font-family: $typeface;
						font-weight: 500;
						color: #333333;
						margin-top: 12upx;
						height: 45upx;
						line-height: 45upx;
					}

					.tipTilte1 {
						height: 33upx;
						font-size: 24upx;
						font-family: $typeface1;
						font-weight: 400;
						color: #C1C1C1;
						line-height: 33upx;
						margin-top: 30upx;
					}
				}

				.topRigth {
					width: 136upx;
					height: 100%;

					.cep_1 {
						width: 136upx;
						height: 136upx;
					}
				}
			}
		}

		.bodyBoom {
			height: 96upx;
			width: 624upx;
			margin: auto;

			.botmLeft {
				width: 60%;
				height: 100%;
				font-size: 26upx;
				font-family: $typeface;
				font-weight: 500;
				color: #666666;
			}

			.botmRigth {
				width: 186upx;
				height: 100%;
				font-size: 26upx;
				font-family: $typeface1;
				font-weight: 400;
				color: #44AEFF;

				.jiao {
					width: 10upx;
					height: 16upx;
				}
			}
		}
	}

	
</style>
